'use strict';
module.exports = {
	/**
	 * 充值学习币
	 * @url admin/system/user/sys/chargeCoin 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid, number, _id } = data;
		let res = { code: 0, msg: "" };
		// 业务逻辑开始-----------------------------------------------------------

		let info = await vk.baseDao.findById({
			dbName: "uni-id-users",
			id: _id
		});
		let num = Number(info.coin) + number + ''
		await vk.baseDao.updateById({
			dbName: "uni-id-users",
			id: _id,
			dataJson: { coin: num }
		})

		// 添加记录
		await vk.baseDao.add({
			dbName: "study_coin_count", // 表名
			dataJson: {
				uid: _id,
				chargeId: uid,
				useOrRecharge: 'admin',
				number
			}
		})

		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
